<!DOCTYPE HTML>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>

promise_test(function() {
  assert_idl_attribute(navigator, 'mediaDevices');
  assert_idl_attribute(navigator.mediaDevices, 'getUserMedia');

  return navigator.mediaDevices.getUserMedia({audio: true}).then(function(s) {
    assert_equals(s.getTracks().length, 1);
  });
}, 'getUserMedia() audio track');

promise_test(function() {
  assert_idl_attribute(navigator, 'mediaDevices');
  assert_idl_attribute(navigator.mediaDevices, 'getUserMedia');

  return navigator.mediaDevices.getUserMedia({audio: true, video:true})
      .then(function(s) {
    assert_equals(s.getTracks().length, 2);
    assert_equals(s.getAudioTracks().length, 1);
    assert_equals(s.getVideoTracks().length, 1);
  });
}, 'getUserMedia() audio and video tracks');

promise_test(function() {
  return navigator.mediaDevices.getUserMedia(
      {audio: {'mandatory': { 'valid_but_unsupported_1': 0}}})
  .then(function(s) {
    fail('getUserMedia should have failed');
  }).catch(function(e) {
    assert_equals(e.name, 'OverconstrainedError');
    assert_equals(e.constraint, 'valid_but_unsupported_1');
  });
}, 'getUserMedia() with unsupported mandatory constraint');


</script>
</body>
</html>
